package com.neusoft.elm.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.neusoft.elm.dao.AdminDao;
import com.neusoft.elm.po.Admin;
import com.neusoft.elm.util.DBUtil;

public class AdminDaoImpl implements AdminDao{
	
	Connection con = null;
	PreparedStatement pst = null;
	ResultSet rs = null;

	@Override 
	public Admin getAdminByNameByPass(String adminName, String password) {
		// TODO 右侧会有小蓝点， 点击会跳转提示
		// TODO 工  作打断的时候可以用这个记录
		// TODO 等恢复工作的时候可以继续续写代码
		Admin admin = null;
		String sql = "SELECT * FROM admin WHERE adminName = ? AND password = ?";
		
		try {
			//1.链接数据库
			con = DBUtil.getConnection();
			pst = con.prepareStatement(sql);
			pst.setString(1, adminName);
			pst.setString(2, password);
			rs = pst.executeQuery();
			
			//遍历执行结果
			while(rs.next()){
				admin = new Admin();
				admin.setAdminId(rs.getInt("adminId"));
				admin.setAdminName(rs.getString("adminName"));
				admin.setPassword(rs.getString("password"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBUtil.close(rs, pst, con);
		}
		
		return admin;
	}

}
